package com.itboye.shopcar_adapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import com.itboye.config.GlobalConfig;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.core.utils.XImageLoader;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.ui.aizhiwu.GeRenActivity;
import com.itboye.mengwu.data.model.FenSiBean;
import com.itboye.mengwu.data.model.FenSiBean.FenSiModel;
import com.itboye.mengwu.data.model.MessgeBean;
import com.itboye.mengwu.data.model.RedBagModel;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

@SuppressLint("ResourceAsColor")
public class MeGuanZhuAdapter extends BaseAdapter {
	FenSiBean list;
	Context context;

	// OnClickListener clickListener;
	public MeGuanZhuAdapter(FenSiBean list, Context context) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.getList() == null ? 0 : list.getList().size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View ContextView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		HouderView houderView;
		if (ContextView == null) {
			houderView = new HouderView();
			ContextView = LayoutInflater.from(context).inflate(
					R.layout.item_meguanzhu, null);
			houderView.queryPersonData = (ImageView) ContextView
					.findViewById(R.id.imgGuanzhu);
			houderView.txtCountext = (TextView) ContextView
					.findViewById(R.id.txtGuanzhuTitle);
			houderView.txtname = (TextView) ContextView
					.findViewById(R.id.txtGuanzhuTime);
			houderView.txtnamew = (TextView) ContextView
					.findViewById(R.id.txtnamew);
			ContextView.setTag(houderView);

		} else {
			houderView = (HouderView) ContextView.getTag();
		}
		// FenSiModel Fensomdoel=list.get(arg0);
		// XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
		// + list.getList().get(arg0).getHead(),
		// houderView.queryPersonData);
		if (list.getList().get(arg0).getHead() == null
				|| "".equals(list.getList().get(arg0).getHead())) {
			if ("1".equals(list.getList().get(arg0).getSex())) {
				// imageView.setImageResource(R.drawable.male);
				houderView.queryPersonData
						.setBackgroundResource(R.drawable.male);
			} else {
				houderView.queryPersonData.setImageResource(R.drawable.female);
			}
		} else {
			if (!list.getList().get(arg0).getHead().startsWith("http")) {
				XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
						+ list.getList().get(arg0).getHead(),
						houderView.queryPersonData);
			} else {
				XImageLoader.load(list.getList().get(arg0).getHead(),
						houderView.queryPersonData);
			}

		}
		houderView.queryPersonData.setTag(arg0);
		houderView.queryPersonData.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(context, GeRenActivity.class);
				intent.putExtra("uid",
						SPUtils.get(context, null, SpPublicParams.UID, "") + "");
				intent.putExtra("fromUid", list.getList().get((int) v.getTag())
						.getUid()
						+ "");
				context.startActivity(intent);
			}
		});
		houderView.txtCountext.setText(list.getList().get(arg0).getNickname());
		houderView.txtnamew.setText(list.getList().get(arg0).getSign());
		houderView.txtname
				.setText(new SimpleDateFormat("yyyy-MM-dd").format(Long
						.parseLong(list.getList().get(arg0).getFocus_time()) * 1000));
		// houderView.txtGuanzhu.setText(list.getList().get(arg0).getIs_focus_back());
		// if(Integer.parseInt(list.getList().get(arg0).getIs_focus_back())==0){
		// houderView.txtGuanzhu.setText("已关注");
		// houderView.txtGuanzhu.setTag(R.id.tag_first,"0");
		// houderView.txtGuanzhu.setTextColor(R.color.gray);
		// }else
		// if(Integer.parseInt(list.getList().get(arg0).getIs_focus_back())==1){
		// houderView.txtGuanzhu.setText("关注");
		// houderView.txtGuanzhu.setTextColor(R.color.main_color);
		// houderView.txtGuanzhu.setTag(R.id.tag_first,"1");
		// }
		// houderView.txtGuanzhu.setTag(arg2);
		// houderView.txtGuanzhu.setOnClickListener(clickListener);
		return ContextView;
	}

	class HouderView {
		private TextView txtCountext;
		private TextView txtname;
		private ImageView queryPersonData;
		private TextView txtnamew;
	}

}
